import SocketPromise from "../event/SocketPromise";
import {socketService} from "../socket/WebsocketServiceImpl";


const socketProxy =  new Proxy({}, {
    get: (target, name, receiver) => {
        if(typeof socketService[name] == 'function'){
            return socketService[name].bind(socketService);
        }

        return (reqParams = null) => {
            return new SocketPromise((resolve, reject) => {
                socketService.callMethod(name,reqParams).then((resData)=>{
                    let execFunction = resolve(resData)
                    if(execFunction){
                        socketService.methodNameMap.set(name as string,execFunction);
                    }
                })
            });
        }
    }
})

export default socketProxy;
